package com.mxpio.erp.plm.controller;

import com.mxpio.erp.common.plm.entity.ProjectTaskDraft;
import com.mxpio.erp.common.plm.service.ProjectTaskDraftService;
import com.mxpioframework.common.vo.Result;
import com.mxpioframework.jpa.query.Criteria;
import com.mxpioframework.jpa.query.Operator;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "ProjectTaskController", description = "项目任务计划-草稿表")
@RestController
@RequestMapping("/erp/plm/pro/task/draft/")
public class ProjectTaskDraftServiceController {

    @Autowired
    private ProjectTaskDraftService projectTaskDraftService;

    @GetMapping("list/{taskLogId}")
    @Operation(summary = "根据交付物编码-获取交付物信息", description = "根据交付物编码-获取交付物信息", method = "GET")
    public Result<ProjectTaskDraft> getById(@PathVariable(name = "taskLogId", required = true) String taskLogId) {
        Criteria criteria = Criteria.create();
        criteria.addCriterion("taskLogId", Operator.EQ, taskLogId);
        List<ProjectTaskDraft> list = projectTaskDraftService.list(ProjectTaskDraft.class, criteria);
        if(list.isEmpty()){
            return Result.error("未找到任务变更数据！");
        }
        return Result.OK(list.get(0));
    }


}
